home *** CD-ROM | disk | FTP | other *** search
- _global.Timer = function()
- {
- this.init();
- };
- Timer.prototype.init = function()
- {
- var _loc1_ = this;
- _loc1_.delay = 1000;
- _loc1_.initialDelay = 0;
- _loc1_.ticksCounter = 0;
- _loc1_.hiddenTicksCounter = 0;
- _loc1_.alarm = 0;
- _loc1_.alarms = [];
- _loc1_.sentAlarms = 0;
- _loc1_._listeners = [];
- _loc1_.mcs = [];
- _loc1_.running = false;
- _loc1_.paused = false;
- _loc1_.controlling = false;
- _loc1_.scheduled = false;
- };
- Timer.prototype.setDelay = function(delay)
- {
- var _loc1_ = delay;
- _loc1_ = parseInt(_loc1_);
- if(isNaN(_loc1_) || _loc1_ < 1)
- {
- trace("Debugger ::\t(setDelay)\tThe delay value has to be a number greater than 1.");
- return 0;
- }
- this.delay = _loc1_;
- };
- Timer.prototype.setInitialDelay = function(initialDelay)
- {
- var _loc1_ = initialDelay;
- _loc1_ = parseInt(_loc1_);
- if(isNaN(_loc1_) || _loc1_ < 0)
- {
- trace("Debugger ::\t(setInitialDelay)\tThe initial delay value has to be a number greater than 0.");
- return 0;
- }
- this.initialDelay = _loc1_;
- };
- Timer.prototype.getDelay = function()
- {
- return this.delay;
- };
- Timer.prototype.getInitialDelay = function()
- {
- return this.initialDelay;
- };
- Timer.prototype.addListener = function(reference)
- {
- this._listeners[reference] = reference;
- };
- Timer.prototype.removeListener = function(reference)
- {
- delete this._listeners[reference];
- };
- Timer.prototype.sendEvent = function(functionName, params)
- {
- var _loc1_ = this;
- var _loc2_ = functionName;
- var _loc3_ = params;
- for(var i in _loc1_._listeners)
- {
- _loc1_._listeners[i][_loc2_](_loc3_);
- }
- };
- Timer.prototype.isRunning = function()
- {
- return this.running;
- };
- Timer.prototype.isPaused = function()
- {
- return this.paused;
- };
- Timer.prototype.hasSchedule = function()
- {
- return this.scheduled;
- };
- Timer.prototype.hasControl = function()
- {
- return this.controlling;
- };
- Timer.prototype.getControlledMovieclips = function()
- {
- return this.mcs;
- };
- Timer.prototype.start = function()
- {
- var _loc1_ = this;
- if(_loc1_.intervalID)
- {
- clearInterval(_loc1_.intervalID);
- }
- _loc1_.intervalID = setInterval(_loc1_,"tick",_loc1_.delay);
- _loc1_.running = true;
- _loc1_.paused = false;
- _loc1_.sendEvent("onTimerStart");
- _loc1_.startTime = getTimer();
- };
- Timer.prototype.stop = function()
- {
- var _loc1_ = this;
- clearInterval(_loc1_.intervalID);
- _loc1_.running = false;
- _loc1_.sendEvent("onTimerStop");
- };
- Timer.prototype.pause = function()
- {
- var _loc1_ = this;
- if(_loc1_.isRunning())
- {
- _loc1_.paused = true;
- _loc1_.sendEvent("onTimerPause");
- }
- };
- Timer.prototype.sleep = function(sleepPeriod)
- {
- var _loc1_ = this;
- var _loc2_ = sleepPeriod;
- _loc2_ = parseInt(_loc2_);
- if(isNaN(_loc2_) || _loc2_ < 1)
- {
- trace("Debugger ::\t(sleep)\tThe sleepPeriod value has to be a number greater than 1.");
- return 0;
- }
- if(_loc1_.isRunning())
- {
- _loc1_.paused = true;
- _loc1_.sleepDuration = _loc1_.getTicksDifference() + _loc2_;
- _loc1_.sendEvent("onTimerSleep");
- }
- };
- Timer.prototype.resume = function()
- {
- var _loc1_ = this;
- if(_loc1_.isRunning() && _loc1_.isPaused())
- {
- _loc1_.paused = false;
- _loc1_.sendEvent("onTimerResume");
- }
- };
- Timer.prototype.reset = function()
- {
- var _loc1_ = this;
- _loc1_.ticksCounter = 0;
- _loc1_.hiddenTicksCounter = 0;
- _loc1_.sentAlarms = 0;
- _loc1_.sendEvent("onTimerReset");
- };
- Timer.prototype.getTicksCount = function()
- {
- return this.ticksCounter;
- };
- Timer.prototype.getHiddenTicksCount = function()
- {
- return this.hiddenTicksCounter;
- };
- Timer.prototype.getTicksDifference = function()
- {
- var _loc1_ = this;
- _loc1_.ticksDifference = _loc1_.getHiddenTicksCount() - _loc1_.getTicksCount();
- return _loc1_.ticksDifference;
- };
- Timer.prototype.setAlarm = function(alarm)
- {
- var _loc1_ = alarm;
- _loc1_ = parseInt(_loc1_);
- if(isNaN(_loc1_) || _loc1_ < 1)
- {
- trace("Debugger ::\t(setAlarm)\tThe alarm value has to be a number greater than 1.");
- return 0;
- }
- this.alarm = _loc1_;
- this.hasAlarm = true;
- };
- Timer.prototype.getAlarm = function()
- {
- return this.alarm + 1;
- };
- Timer.prototype.setAlarms = function()
- {
- var _loc2_ = arguments;
- var _loc3_ = this;
- var _loc1_ = 0;
- while(_loc1_ < _loc2_.length)
- {
- _loc2_[_loc1_] = parseInt(_loc2_[_loc1_]);
- if(isNaN(_loc2_[_loc1_]) || _loc2_[_loc1_] < 1)
- {
- trace("Debugger ::\t(setAlarms)\tThe alarm value has to be a number greater than 1.");
- return 0;
- }
- _loc3_.alarms.push(_loc2_[_loc1_]);
- _loc1_ = _loc1_ + 1;
- }
- _loc3_.hasMultipleAlarms = true;
- };
- Timer.prototype.getAlarms = function()
- {
- return this.alarms;
- };
- Timer.prototype.getAccuracy = function()
- {
- var _loc1_ = this;
- return (getTimer() - _loc1_.startTime) / _loc1_.getHiddenTicksCount() - _loc1_.getDelay();
- };
- Timer.prototype.controlTimelineOf = function()
- {
- var _loc2_ = arguments;
- var _loc3_ = this;
- var _loc1_ = 0;
- while(_loc1_ < _loc2_.length)
- {
- if(_loc2_[_loc1_] instanceof movieclip != 1)
- {
- trace("Debugger::\t(controlTimelineOf)\tThe parameter has to be the instance name of a movie-clip.");
- return 0;
- }
- _loc3_.mcs.push(_loc2_[_loc1_]);
- _loc2_[_loc1_].stop();
- _loc1_ = _loc1_ + 1;
- }
- _loc3_.controlling = true;
- };
- Timer.prototype.releaseTimelineOf = function(mc, stopMC)
- {
- var _loc2_ = this;
- var _loc3_ = mc;
- var _loc1_ = 0;
- while(_loc1_ < _loc2_.mcs.length)
- {
- if(_loc2_.mcs[_loc1_] == _loc3_)
- {
- delete _loc2_.mcs[_loc1_];
- }
- _loc1_ = _loc1_ + 1;
- }
- !stopMC ? _loc3_.play() : _loc3_.stop();
- if(_loc2_.mcs.length < 1)
- {
- _loc2_.controlling = false;
- }
- };
- Timer.prototype.schedule = function(handler, methodName, param)
- {
- var _loc1_ = this;
- _loc1_.handler = handler;
- _loc1_.methodName = methodName;
- _loc1_.param = param;
- _loc1_.scheduled = true;
- };
- Timer.prototype.clearSchedule = function()
- {
- this.scheduled = false;
- };
- Timer.prototype.execute = function()
- {
- var _loc1_ = this;
- _loc1_.handler[_loc1_.methodName](_loc1_.param);
- };
- Timer.prototype.tick = function()
- {
- var _loc1_ = this;
- if(_loc1_.hasAlarm)
- {
- if(_loc1_.getTicksCount() == _loc1_.alarm)
- {
- _loc1_.sendEvent("onTimerAlarm");
- }
- }
- if(_loc1_.hasMultipleAlarms)
- {
- var _loc3_ = 0;
- while(_loc3_ < _loc1_.alarms.length)
- {
- if(_loc1_.getTicksCount() == _loc1_.alarms[_loc1_.sentAlarms])
- {
- _loc1_.sendEvent("onTimerAlarms",_loc1_.sentAlarms++);
- }
- _loc3_ = _loc3_ + 1;
- }
- }
- if(_loc1_.isPaused() && _loc1_.getTicksDifference() == _loc1_.sleepDuration)
- {
- _loc1_.resume();
- }
- if(_loc1_.hasControl())
- {
- var _loc2_ = 0;
- while(_loc2_ < _loc1_.mcs.length)
- {
- _loc1_.mc = _loc1_.mcs[_loc2_];
- !_loc1_.isPaused() ? _loc1_.mc.gotoAndStop(_loc1_.mc._currentframe != _loc1_.mc._totalframes ? _loc1_.mc._currentframe + 1 : _loc1_.mc._currentframe - _loc1_.mc._totalframes + 1) : _loc1_.mc.stop();
- _loc2_ = _loc2_ + 1;
- }
- updateAfterEvent();
- }
- if(_loc1_.getHiddenTicksCount() >= _loc1_.initialDelay)
- {
- if(!_loc1_.isPaused() && _loc1_.isRunning())
- {
- _loc1_.sendEvent("onTimerTick",++_loc1_.ticksCounter);
- }
- }
- if(_loc1_.isRunning())
- {
- _loc1_.hiddenTicksCounter = _loc1_.hiddenTicksCounter + 1;
- }
- if(_loc1_.hasSchedule() && _loc1_.getHiddenTicksCount() >= _loc1_.initialDelay)
- {
- _loc1_.execute();
- }
- };
-